<?php
namespace app\souther\controller;

use app\common\model\WechatConfig;
use think\Db;

class Wechat extends Base
{
	
	function __construct()
	{
		parent::_initialize();
	}
	/**
     * [index  配置]
     * @author [南風]
     * @return mixed|string
     * @throws \Exception
     */
	public function config()
	{
		$model = new WechatConfig();
		
		if(request()->isPost()){
			try{
                $param = input('post.');
                if($param['id']==''){
                    $id = $model->addData($param);
                }else{
                    $id = $model->editData($param);
                }
            }catch(\Exception $e){
                writelog($e->getMessage(),-1);
                return admin_json(-1,$model->getError());
            }
            writelog('公众号配置--'.$id);
            return admin_json(1,'成功','',url('/wechat_config'));
		}
		 
		$wechat_config = $model->find();
		$wechat_config['wx_url'] = config('web_url.').'token';
		return $this->fetch('',['edit'=>$wechat_config]);
	}
}